package com.xc.c1

object singleDog {

  def main(args: Array[String]): Unit = {
    val dog = Dog
    println(dog.toString)
  }
}

class Dog private{

}

object Dog{
  var singleDog:Dog = null

  def apply(): Dog = {
    if(singleDog == null){
      singleDog = new Dog
    }
    singleDog
  }

  override def toString: String = {
    println("single dog")
    super.toString
  }

}
